package com.sphd.restaurantsystem.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sphd.restaurantsystem.R;
import com.sphd.restaurantsystem.info.CouponMsgInfo;
import com.wzh.frame.utils.TimeUtils;

import java.util.List;

/**
 * Created by Hu on 2016/12/19.
 */

public class CouponMsgAdapter extends BaseAdapter {
    private List<CouponMsgInfo> couponInfoList;
    private Context context;
    private int layoutint;

    public CouponMsgAdapter (Context context , List<CouponMsgInfo> couponInfoList, int layoutint){

        this.context=context;
        this.couponInfoList=couponInfoList;
        this.layoutint=layoutint;
    }


    @Override
    public int getCount() {
        return couponInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return couponInfoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolderCoupon viewHolderCoupon=null;

        if(viewHolderCoupon==null){

            viewHolderCoupon= new ViewHolderCoupon();
            convertView = View.inflate(context,layoutint,null);
            viewHolderCoupon.date= (TextView) convertView.findViewById(R.id.coupon_date);
            viewHolderCoupon.message= (TextView) convertView.findViewById(R.id.coupon_message);
            convertView.setTag(viewHolderCoupon);
        }else {
            viewHolderCoupon= (ViewHolderCoupon) convertView.getTag();
        }
        viewHolderCoupon.date.setText(TimeUtils.getTime(couponInfoList.get(position).getProm_regtime(),TimeUtils.DATE_FORMAT_DATE));
        viewHolderCoupon.message.setText(couponInfoList.get(position).getProm_info());

        return convertView;
    }

    class  ViewHolderCoupon{
        TextView date;
        TextView message;

    }
}
